<html>
<head><meta charset="utf-8"><title>Async &quot;block&quot;? · wg-async-foundations · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/index.html">wg-async-foundations</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html">Async &quot;block&quot;?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="170558788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170558788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170558788">(Jul 10 2019 at 16:59)</a>:</h4>
<p>Is the async block really a thing? What’s the motivation for it to not share syntax with closures?</p>



<a name="170559066"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170559066" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170559066">(Jul 10 2019 at 17:01)</a>:</h4>
<p>The RFC suggests that my initial assumption about what async blocks are was correct. I guess we Ruby now.</p>



<a name="170559738"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170559738" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Gilcher <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170559738">(Jul 10 2019 at 17:08)</a>:</h4>
<p>I'm fine with "Ruby"ing, even if I don't know what the term means?</p>



<a name="170559785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170559785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170559785">(Jul 10 2019 at 17:09)</a>:</h4>
<p>Ostensibly it means "Taking inspiration from Ruby's design"?</p>



<a name="170560125"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170560125" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170560125">(Jul 10 2019 at 17:12)</a>:</h4>
<blockquote>
<p>What’s the motivation for it to not share syntax with closures?</p>
</blockquote>
<p><span class="user-mention" data-user-id="123586">@nagisa</span> there's a semantic difference here; <code>async { ... }</code> makes an <code>impl Future</code> whereas <code>async || ..</code> makes a closure that makes an <code>impl Future</code></p>



<a name="170560150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170560150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170560150">(Jul 10 2019 at 17:13)</a>:</h4>
<p>Tho async closures may be the redundant thing</p>



<a name="170560181"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170560181" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170560181">(Jul 10 2019 at 17:13)</a>:</h4>
<p>I was refering to ruby’s syntax being full of magic, often unnecessary magic, and thus being less easy to deal with.</p>



<a name="170560330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170560330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170560330">(Jul 10 2019 at 17:15)</a>:</h4>
<blockquote>
<blockquote>
<p>What’s the motivation for it to not share syntax with closures?</p>
</blockquote>
<p><span class="user-mention silent" data-user-id="123586">nagisa</span> there's a semantic difference here; <code>async { ... }</code> makes an <code>impl Future</code> whereas <code>async || ..</code> makes a closure that makes an <code>impl Future</code></p>
</blockquote>
<p>Hmm, okay. Still feels weird. In my head <code>async {}</code> eventually becomes just the body of <code>Future::poll</code> after some generator-like transformations and whatnot. Or something similar.</p>



<a name="170560338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170560338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170560338">(Jul 10 2019 at 17:15)</a>:</h4>
<p>It is still semantically a function.</p>



<a name="170561558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170561558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170561558">(Jul 10 2019 at 17:30)</a>:</h4>
<p>Yes sure, that much is true, tho there's one less level of indirection.</p>
<p><span class="user-mention" data-user-id="123586">@nagisa</span>  I prefer to think in more monadic terms; <code>impl Future&lt;...&gt;</code> being a container with a value inside</p>



<a name="170561585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170561585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> centril <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170561585">(Jul 10 2019 at 17:30)</a>:</h4>
<p>so "it's still semantically a function" is taking a more "low level" perspective</p>



<a name="170565410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170565410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170565410">(Jul 10 2019 at 18:13)</a>:</h4>
<p>Hmm, I too find async block fairly natural -- an "async thing" is something that, when you interact with it "normally", you get back a future to the result instead of the original.</p>
<p>So an <code>async fn</code> is a function that, when called, gives you a future (instead of the result).</p>
<p>Similarly an <code>async { .. }</code> is a block that, when executed, gives you a future (instead of the result).</p>
<p>An async closure <code>async ||</code> then is a closure that, when called, gives you a future (instead of the result). </p>
<p>Similarly <code>async fn foo()</code> and <code>fn foo() { async { } }</code> are basically equivalent, as is <code>async || { ... }</code> and <code>|| async  ... }</code>.</p>



<a name="170567511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170567511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170567511">(Jul 10 2019 at 18:37)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> but it acts nothing like a block – or rather scope – that we have currently. That’s where most of my "ewww" reaction is coming from.</p>



<a name="170567568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170567568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170567568">(Jul 10 2019 at 18:38)</a>:</h4>
<p>how so?</p>



<a name="170567585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170567585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170567585">(Jul 10 2019 at 18:38)</a>:</h4>
<p>it produces a value which, when awaited, executes</p>



<a name="170567591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170567591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170567591">(Jul 10 2019 at 18:38)</a>:</h4>
<p>I find the limitations around control flow inside <code>async {}</code> unnatural, for one.</p>



<a name="170567633"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170567633" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170567633">(Jul 10 2019 at 18:39)</a>:</h4>
<p><code>async {}</code> looks and feels like it ought to behave like the usual scope, but I now know that it is not the case.</p>



<a name="170567785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170567785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170567785">(Jul 10 2019 at 18:40)</a>:</h4>
<p>(I do understand where those limitations are coming from, what I disagree with is the syntactic representation of whatever produces this <code>impl Future</code>).</p>



<a name="170567840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170567840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170567840">(Jul 10 2019 at 18:41)</a>:</h4>
<p>Perhaps it is easiest to compare it with <code>unsafe {}</code> vs <code>{}</code> – both still act like your plain scopes. Hope that makes sense.</p>



<a name="170567866"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187312-wg-async-foundations/topic/Async%20%22block%22%3F/near/170567866" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187312-wg-async-foundations/topic/Async.20.22block.22.3F.html#170567866">(Jul 10 2019 at 18:41)</a>:</h4>
<p>(I do also understand that there is nothing I can change here at this point, since the RFC got accepted a long time ago and its my own fault I didn’t follow it)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>